﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using KEEPER_BRR_13dotNET.Presentation;
using KP_CommonLibrary;
using KP_CommonLibrary.KP_ObjectReferences;
using System.Globalization;
using System.Threading;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
using KP_CommonLibrary.KP_Business;

namespace KEEPER_BRR_13dotNET
{

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>

        #region GetDiffSeverTime
        public static long GetDiffSeverTime()
        {
            try
            {
                string sql = "SELECT GETDATE() AS DateSV";
                DateTime nowData = DateTime.Now;
                DateTime sqlDate = (DateTime)SqlHelper.ExecuteScalar(KP_OCnnSql.Cnn_String, CommandType.Text, sql);
                return (long)sqlDate.Subtract(nowData).TotalMilliseconds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return 0;
        }
        #endregion
        
        [STAThread]
        
        static void Main()
        {
            KP_OCnnSql.Server_Name = KEEPER_BRR_13dotNET.Properties.Settings.Default.Server_Name;
            KP_OCnnSql.Server_User = KEEPER_BRR_13dotNET.Properties.Settings.Default.Server_User;
            KP_OCnnSql.Server_Pass = KEEPER_BRR_13dotNET.Properties.Settings.Default.Server_Pass;
            KP_OCnnSql.Server_DbName = KEEPER_BRR_13dotNET.Properties.Settings.Default.Server_DbName;
            KP_OCnnSql.Gen_CnnString();
            
            
            CultureInfo cu = (CultureInfo)Thread.CurrentThread.CurrentUICulture.Clone();
            CultureInfo ci = new CultureInfo("vi-VN");
            cu.DateTimeFormat = ci.DateTimeFormat;
            cu.NumberFormat.CurrencySymbol = ci.NumberFormat.CurrencySymbol;
            cu.NumberFormat.CurrencyPositivePattern = 3;
            Thread.CurrentThread.CurrentUICulture = cu;
            Thread.CurrentThread.CurrentCulture = cu;
            CauHinh.LoadCauHinh();
            KP_SYS_VARIABLE.M_CLIENT0 = Environment.UserDomainName + " # " + Environment.UserName; ;
            KP_SYS_VARIABLE.M_DIFF_SERVER_TIME = GetDiffSeverTime();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Frm_NhanHoSo2 frm = new Frm_NhanHoSo2();
            //frm.MaLoaiHoSo = "CL";
            //frm.Text = "CL";
            //frm.ShowDialog();
            //frm.MaLoaiHoSo = "TD";
            //frm.Text = "TD";
            //frm.ShowDialog();
            //frm.MaLoaiHoSo = "TN";
            //frm.Text = "TN";
            //frm.ShowDialog();
            //frm.MaLoaiHoSo = "CD";
            //frm.Text = "CD";
            //frm.ShowDialog();
            frm.MaLoaiHoSo = "TDCL";
            frm.Text = "TDCL";
            frm.NhanHoSo("TDCL", "0");
            frm.ShowDialog();
            
            FrmLogin frmLogin = new FrmLogin();
            if (frmLogin.ShowDialog() == DialogResult.OK)
                Application.Run(new FrmMain());
        }
    }

    public static class CauHinh
    {
        public static Dictionary<string, object> _CauHinh = new Dictionary<string, object>();
        public static void LoadCauHinh()
        {
            KP_BLListBase blBase = new KP_BLListBase("tblCauHinh");
            DataTable tblCauHinh = blBase.Select();
            foreach (DataRow row in tblCauHinh.Rows)
                _CauHinh.Add(row["Ten_Bien"].ToString(), row["Gia_Tri"]);
        }
        public static string MaViTri1()
        {
            return _CauHinh["MA_VT1"].ToString();
        }
        public static string TrangThaiHsMacDinh()
        {
            return _CauHinh["HOSO_TT_MAC_DINH"].ToString();
        }
        public static string QuanSuDung()
        {
            return _CauHinh["QUAN_SU_DUNG"].ToString();
        }
        public static string TinhSuDung()
        {
            return _CauHinh["TINH_SU_DUNG"].ToString();
        }
        public static string MaHKD()
        {
            return _CauHinh["MA_HKD"].ToString();
        }
    }
}
